﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using UnobtrusiveAjax.Models;
using System.Threading;

namespace Home.WebUI.Areas.Example.Controllers
{
    public class UnobtusiveAjaxController : Controller
    {
        //参考 http://www.cnblogs.com/mszhangxuefei/archive/2012/06/01/mvcnotes_32.html
        //
        // GET: /Appointment/

        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Index(string id)
        {
            return View("Index", (object)id);
        }
        private void test()
        { 
        
        }
        public ViewResult AppointmentData(string id)
        {
            //加个时间响应
            Thread oThread = new Thread(new ThreadStart(test));
            oThread.Start();
            Thread.Sleep(10 * 1000);
            oThread.Abort();
            IEnumerable<Appointment> data = new[] {
                 new Appointment { ClientName = "张三", Date = DateTime.Parse("1/1/2012")}, 
                 new Appointment { ClientName = "李四", Date = DateTime.Parse("2/1/2012")}, 
                 new Appointment { ClientName = "王五", Date = DateTime.Parse("3/1/2012")}, 
                 new Appointment { ClientName = "赵六", Date = DateTime.Parse("1/20/2012")}, 
                 new Appointment { ClientName = "田七", Date = DateTime.Parse("1/22/2012")}, 
                 new Appointment {ClientName = "黄九", Date = DateTime.Parse("2/25/2012")}, 
                 new Appointment {ClientName = "路人甲", Date = DateTime.Parse("2/25/2013")}
            };
            if (!string.IsNullOrEmpty(id) && id != "All")
            {
                data = data.Where(e => e.ClientName == id);
            }
            return View(data);
        }


    }
}
